<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'easyuilist.jsp' starting page</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">

	var url;
	
	function searchTeam(){
		$("#dg").datagrid('load',{
			"name":$("#name").val()
		});
	}
	
	function deleteTeam(){
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];
		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].userid);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确认要删除这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				$.post("${pageContext.request.contextPath}/team/remove.do",
						{ids:ids},
						function(result){
							if(result.success){
								$.messager.alert("系统提示","数据已成功删除！");
								$("#dg").datagrid("reload");
							}else{
								$.messager.alert("系统提示","数据删除失败！");
						}
						},
						"json");
			}
		});
		
	}
	
	
	function openOrgAddDialog(){
		$("#dlg").dialog("open").dialog("setTitle","添加用户组信息");
		url="${pageContext.request.contextPath}/org/save.do";
	}
	
	
	function saveOrg(){
		$("#fm").form("submit",{
			url:url,
			onSubmit:function(){
				/* if($("#name").val("getValue")==""){
				var aaa=$("#name").val();
					$.messager.alert("系统提示","用户组名不能为空"+aaa+"111");
					return false;
				} */
				return $(this).form("validate");
			},
			success:function(result){
				var result=eval('('+result+')');
				if(result.success){
					$.messager.alert("系统提示","保存成功");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败");
					return;
				}
			}
		});
	}
	
	function openTeamModifyDialog(){
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length!=1){
			$.messager.alert("系统提示","请选择一条要编辑的数据！");
			return;
		}
		var row=selectedRows[0];
		$("#dlg").dialog("open").dialog("setTitle","编辑用户组信息");
		$('#fm').form('load',row);
		url="${pageContext.request.contextPath}/team/edit.do?userid="+row.userid;
	}
	
	function resetValue(){
		$("#name").val("");
		$("#number").val("");
		$("#pid").val("");
	}
	
	function closeTeamDialog(){
		$("#dlg").dialog("close");
		resetValue();
	}
</script>
</head>
<body>
	<table id="dg" title="用户组管理" class="easyui-datagrid"
		 fitColumns="true" pagination="true" rownumbers="true"
		 url="${pageContext.request.contextPath}/org/list.do" fit="true" toolbar="#tb">
		 <thead>
	 		<tr>
	 			<th field="cb" checkbox="true" align="center"></th>
	 			<th field="id" width="50" align="center">编号</th>
	 			<th field="name" width="100" align="center">用户组名</th>
	 			<th field="number" width="100" align="center">组号</th>
	 			<th field="parentId" width="100" align="center">父组</th>
	 		</tr>
	 	</thead>
	</table>
	
	<div id="tb">
		<div>
			<a href="javascript:openOrgAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
			<a href="javascript:openTeamModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:deleteTeam()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
			&nbsp;用户组名：&nbsp;<input type="text" id="name" size="20" onkeydown="if(event.keyCode==13) searchTeam()"/>
			<a href="javascript:searchTeam()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
		</div>
	</div>
	
	<div id="dlg" class="easyui-dialog" style="width: 620px;height:250px;padding: 10px 20px"
	  closed="true" buttons="#dlg-buttons">
	 	<form id="fm" method="post">
	 		<table cellspacing="8px">
	 			<tr>
	 				<td>组织名：</td>
	 				<td><input type="text" id="name" name="name" class="easyui-validatebox" required="true"/>&nbsp;<font color="red">*</font></td>
	 			</tr>
	 			<tr>
	 				<td>组号：</td>
	 				<td><input type="text" id="number" name="number" class="easyui-numberbox" required="true"/>&nbsp;<font color="red">*(数字)</font></td>
	 			</tr>
	 			<tr>
	 				<td>父组：</td>
	 				<td><input type="text" id="parentId" name="parentId" class="easyui-validatebox" required="true"/>&nbsp;<font color="red">*</font></td>
	 			</tr>
	 		</table>
	 	</form>
	</div>
	<div id="dlg-buttons">
		<a href="javascript:saveOrg()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeTeamDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
</body>

</html>
